{# Copyright 2014-2015 Siemens AG

   Copying and distribution of this file, with or without modification,
   are permitted in any medium without royalty provided the copyright notice and this notice are preserved.
   This file is offered as-is, without any warranty.
#}
  <script src="scripts/job-queue-poll.js" type="text/javascript"></script>
  <script>
    var resultEntity = $("#jobResult");

    function linkDownloadReport() {
      resultEntity.html("<a href='{{ downloadLink }}'>Download {{ reportType }} report</a>");
      window.location = "{{ downloadLink }}";
    }
    function genereationFailed(jqPk) {
      var text = (jqPk > 0) ? linkToJob(jqPk) : "no job scheduled";
      resultEntity.html("{{ reportType }} generation failed: " + text);
    }

    function addLinkAndQueueAjaxPolling() {
      var jqPk = {{ jqPk }};
      if (jqPk > 0)
      {
        resultEntity.html("{{ reportType }} report generation scheduled as " + linkToJob(jqPk));
        queueUpdateCheck(jqPk, linkDownloadReport, genereationFailed);
      }
      else
      {
        genereationFailed();
      }
    }

    $(document).ready(function () {
      addLinkAndQueueAjaxPolling();
    });
  </script>
